# Notify.py
# Copyright (C) otacon 2010 <orfeo18@gmail.com>
# 
# AdSense-Monitor is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# AdSense-Monitor is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

import gtk
import os
import datetime
import pynotify
from core import Path

class Notification():
    """
    Class to show notifications
    """
    def __init__(self, configuration):
        """
        constructor
        a dictionary returns a tuple that sets: <is_shown>,<notify_on_update>,<value>
        """
        self.config = configuration
        self.notifications=[]
        pynotify.init("Adsense-Monitor")


    def show_notify(self,message):
        """method to show pynotify with data"""
        
        notification = pynotify.Notification("Adsense-Monitor", message)
        notification.set_hint_string ("x-canonical-append", "allowed")
        image = os.path.join(Path.DATA_PATH,'ok.png')
        pixbuf = gtk.gdk.pixbuf_new_from_file(image)
        notification.set_icon_from_pixbuf(pixbuf)

        try:
            notification.show()
        except gobject.GError:
            print "can't display notification" # TODO, retry?
            return
        notification.connect('closed', self.on_notify_close)
        self.notifications.append(notification)

    def on_notify_close(self, n, fedora_wtf=None):
        if n in self.notifications:
            self.notifications.remove(n)
